/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MUDITEM_H
#define MUDITEM_H

#include "MudObject.h"

namespace Chronos {

class StringBuilder;

class MudItem : public MudObject {
public:
    MudItem(int type_, const std::string& name_, const std::string& descr_, int weight_);
    MudItem(const MudItem& rhs);
    virtual void accept(CmdVisitor& v);

    bool canPickup(MudPlayer& player);
	void pickup();

    int getWeight() const;
    int getType() const;

    virtual void serialize(StringBuilder& buffer) const;
protected:
    int weight;
    int type;
private:
    MudItem& operator=(const MudItem&);
};


class ItemFactory {
public:
    virtual ~ItemFactory() {}
    virtual MudItem& create() const = 0;
};


class ItemDb;

class ItemDbFactory : public ItemFactory {
public:
    ItemDbFactory(const ItemDb& db_, int id_);
    virtual MudItem& create() const;
private:
    const ItemDb& db;
    int id;
};


template <typename T>
class CustomItemFactory : public ItemFactory {
public:
    CustomItemFactory(const T& t) : prototype(t) {}
    virtual MudItem& create() const {
        return *new T(prototype);
    }
private:
    const T prototype;
};

typedef CustomItemFactory<MudItem> MudItemFactory;

}

#endif

